import requests
from lxml import etree

cookies = {
    'Hm_lvt_ab0153f5f064a819a91a3699f63f86e3': '1699602345',
    'Hm_lpvt_ab0153f5f064a819a91a3699f63f86e3': '1699602695',
}

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    # 'Cookie': 'Hm_lvt_ab0153f5f064a819a91a3699f63f86e3=1699602345; Hm_lpvt_ab0153f5f064a819a91a3699f63f86e3=1699602695',
    'Referer': 'http://spiderbuf.cn/list',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
}

response = requests.get('http://spiderbuf.cn/s01/', cookies=cookies, headers=headers, verify=False)

element = etree.HTML(response.text)

trs = element.xpath('//tr')

f = open('lxml库入门.txt','w',encoding='utf-8')

for item in trs:
    tds = item.xpath('./td')
    inline_str=''
    for td in tds:
        inline_str += f"{td.text}\t|"
    f.write(inline_str+"\n")
    print(inline_str)
f.close()